//
//  UILabel+CLExtension.m
//  togetherLBS
//
//  Created by 丁益 on 16/6/22.
//  Copyright © 2016年 celi. All rights reserved.
//

#import "UILabel+CLExtension.h"

@implementation UILabel (CLExtension)

// 设置某段字的颜色
- (void)setColor:(UIColor *)color fromIndex:(NSInteger)location length:(NSInteger)length{

//    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:self.text];
    
    NSMutableAttributedString *str = (NSMutableAttributedString*)self.attributedText;
    [str addAttribute:NSForegroundColorAttributeName value:color range:NSMakeRange(location,length)];
    self.attributedText = str;

}

// 设置某段字的字体
- (void)setFont:(UIFont *)font fromIndex:(NSInteger)location length:(NSInteger)length{

//    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:self.text];
    
    NSMutableAttributedString *str = (NSMutableAttributedString*)self.attributedText;
    [str addAttribute:NSFontAttributeName value:font range:NSMakeRange(location, length)];

    /*[str addAttribute:(NSString *)kCTUnderlineStyleAttributeName
                       value:(id)[NSNumber numberWithInt:style]
                       range:NSMakeRange(location, length)];*/
    self.attributedText = str;
}

// 设置某段字的风格  （添加下划线）
- (void)setStyle:(CTUnderlineStyle)style fromIndex:(NSInteger)location length:(NSInteger)length{
    NSMutableAttributedString *str = (NSMutableAttributedString*)self.attributedText;
    
    [str addAttribute:(NSString *)kCTUnderlineStyleAttributeName
     value:(id)[NSNumber numberWithInt:style]
     range:NSMakeRange(location, length)];
    
    self.attributedText = str;
}
@end
